package com.fdb.efp.console.api.rest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.fdb.efp.console.service.vo.ImageShowVo;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;

import mp.isrp.api.Encrypt;

@RestController
@RequestMapping("/api")
public class ImageShowController extends AbstractController  {
	/** 【未注册的服务】
	@Autowired
	@Qualifier("lmtIndivAppService")
	private LmtIndivAppService lmtIndivAppService;*/
	
	@Value("${UID}")
	private String uid;
	@Value("${PWD}")
	private String pwd;
	@Value("${AppID}")
	private String appid;
	@Value("${Ocr}")
	private String ocr;
	@Value("${BUSI_AppID}")
	private String busi_appid;
	@Value("${OPR_SERIAL_NO}")
	private String opr_serial_no;
	@Value("${BUSI_TYPE}")
	private String busi_type;
	@Value("${RIGHT}")
	private String right;
	@Value("${PIECE}")
	private String piece;
	@Value("${PIECE_TYPE}")
	private String piece_type;
	@Value("${URLIP}")
	private String urlip;
	@Value("${URLPORT}")
	private String urlport;
	@Value("${CONTROL_URL}")
	private String control_url;
	@Value("${COUNT}")
	private String count;
	
	 /**
	  * 鏌ヨ鐪佺骇鏍囧織淇℃伅
	  * @param 
	  * @return
	  */
		@RequestMapping(value="/lmt/param/image", method=RequestMethod.POST)
		public @ResponseBody ResponseData<ImageShowVo> queryByRFlag(@RequestBody ImageShowVo inImageShowVo) {		
			setUserInfoToVO(inImageShowVo);
			//閫氳繃鎺堜俊鍗忚鍙锋煡璇笟鍔＄殑缂栧彿鍜屼笟鍔＄敓鎴愭椂闂�
						/********/
			/*娴嬭瘯灏嗕笟鍔℃祦姘村拰涓氬姟鍒涘缓鏃堕棿*/
			inImageShowVo.setBusiSerialNo("2618119677");
			inImageShowVo.setCreatedate("20171225");
			inImageShowVo.setLoginUserId("zhangsan");
			inImageShowVo.setLoginUserOrgCode("00001");
			inImageShowVo.setLoginUserLeageOrgCode("0100");
						/********/
			//璋冪敤鎷兼帴鐨勬柟娉�
			String assemble = assemble(inImageShowVo);
			//璋冪敤鍔犲瘑鏂规硶鍔犲瘑澶勭悊
			String urlEncryptPara = getUrlEncryptPara(assemble);
			//鎷兼帴瑕佽闂殑璺緞
			String urlEncrypt=control_url+urlEncryptPara;
			//璁剧疆鍙傛暟鍒皏o涓紝杩斿洖
			inImageShowVo.setUrlSec(urlEncrypt);
			
			return getResponseData(inImageShowVo);
		}
		
		/**鎷艰url璺緞鍙傛暟閮ㄥ垎瀛楃涓�
		 * @return
		 */
		public String assemble(ImageShowVo inImageShowVo) {
			//鑾峰彇瀹㈡埛userid
			String UserID=inImageShowVo.getLoginUserId();
			//鑾峰彇鏈烘瀯鍙�
			String OrgID= inImageShowVo.getLoginUserOrgCode();
			//鑾峰彇娉曚汉缂栫爜
			String CorpID =inImageShowVo.getLoginUserLeageOrgCode();
			//鑾峰彇涓氬姟娴佺▼鍙�
			String busiSerialNoAss =inImageShowVo.getBusiSerialNo();
			//鑾峰彇涓氬姟鍒涘缓鏃堕棿
			String createdateAss=inImageShowVo.getCreatedate();
			StringBuffer sbBuffer= new StringBuffer();
			sbBuffer.append("UID=").append(uid);
			sbBuffer.append("&PWD=").append(pwd);
			sbBuffer.append("&AppID=").append(appid);
			sbBuffer.append("&UserID=").append(UserID);
			sbBuffer.append("&OrgID=").append(OrgID);
			sbBuffer.append("&CorpID=").append(CorpID);
			sbBuffer.append("&OCR=").append(ocr);
			sbBuffer.append("&info");
			sbBuffer.append(count);
			sbBuffer.append("=BUSI_AppID:").append(busi_appid);
			sbBuffer.append(";BUSI_SERIAL_NO:").append(busiSerialNoAss);
			sbBuffer.append(";BUSI_TYPE:").append(busi_type);
			sbBuffer.append(";CREATE_DATE:").append(createdateAss);
			sbBuffer.append(";RIGHT:").append(right);
			return sbBuffer.toString();
		}
		/**url鐨勫弬鏁板姞瀵嗗鐞�
		 * @param urlparm
		 */
		public String getUrlEncryptPara(String urlparm) {
			Encrypt encrypt = new Encrypt();
			Integer integer= new Integer(urlport);
			encrypt.init(urlip, integer);
			String encryptStr = encrypt.encrypt(urlparm);
			return encryptStr;				
		}
}
